<%@ page import="org.acegisecurity.ui.AbstractProcessingFilter" %>
<%@ page import="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter" %>
<%@ page import="org.acegisecurity.AuthenticationException" %>
<html>
<head>
	<title>Login</title>
	<link rel="stylesheet" type="text/css" href="content_pane.css" />	

    <script type="text/javascript" src="formValidation.js">
    </script>
	<script type="text/javascript" language="JavaScript">
		<!--
			/* See http://www.xs4all.nl/~sbpoley/webmatters/formval.html */
			function validateOnSubmit() {
				var elem;
			    var errs=0;
			    // execute all element validations in reverse order, so focus gets
			    // set to the first one in error.
			    //if (!validateEmail  (document.getElementById('members[0].emailAddress.value'), 'inf_emailAddress', true)) errs += 1; 
			    //if (!validatePresent(document.forms.register.familyName,  'inf_familyName'))        errs += 1; 
				
			    if (errs>1)  alert('There are fields which need correction before sending');
			    if (errs==1) alert('There is a field which needs correction before sending');
			
			    return (errs==0);			
	   		}
		//-->
	</script>
</head>
<body>
<form name="loginForm" action="<%=request.getContextPath()%>/j_acegi_security_check" method="post" onSubmit="return validateOnSubmit()">
<table class="editSection">
<tr>
    <td colspan="2" class="sectionHeading">Login</td>
</tr>
<% 
String userName = null;
String errorCode = request.getParameter("login_error");
if ("1".equals(errorCode)) { 
	userName = (String) session.getAttribute(AuthenticationProcessingFilter.ACEGI_SECURITY_LAST_USERNAME_KEY);
%>
	<tr>
	    <td colspan="2" class="error">
	    	Your login attempt was not successful, try again.<BR>
	    	Reason: <%= ((AuthenticationException) session.getAttribute(AbstractProcessingFilter.ACEGI_SECURITY_LAST_EXCEPTION_KEY)).getMessage() %>
	    </td>
	</tr>    
<% 
} else if ("2".equals(errorCode)) { 
	userName = (String) session.getAttribute(AuthenticationProcessingFilter.ACEGI_SECURITY_LAST_USERNAME_KEY);
%>
	<tr>
	    <td colspan="2" class="error">
	    	The page you are trying to access is protected. Please log in.
	    </td>
	</tr>    
<%
}
%>
<tr>
	<td class="editLabel">Username</td>
    <td class="editValue"><input name="j_username" type="text" value="<%=(userName != null ? userName : "")%>" /></td>
</tr>
<tr>
	<td class="editLabel">Password</td>
    <td class="editValue"><input name="j_password" type="password"/></td>
</tr>
<tr>
	<td class="editLabel"></td>
    <td class="editValue"><input type="submit" value="Login" />
    </td>
</tr>
</table>
</form>
</body>
</html>
